<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Music
 */
namespace Music\Controller;
use Music\Controller\PublicController;

/**
 *接口
 */
class MusicController extends PublicController{
	/* 初始化 */
    protected function _initialize(){
		header('Access-Control-Allow-Origin:*');//允许所有来源访问
		header('Access-Control-Allow-Method:POST,GET');//允许访问的方式    
		header("content-Type: text/html; charset=Utf-8"); 
	}
	
	public function chakan(){
		$m_cms_content = M("cms_content");
		$map['id'] = 213;
		$data = $m_cms_content->where($map)->field("value")->find();
		
		
	}
	#把唯一标示改为id
	/* public function weiyi(){
		$m_mall_content = M("mall_content");
		$map['type'] = 16;
		$list = $m_mall_content->where($map)->select();
		foreach($list as $i=>$v){
			$data['isrc'] = $list[$i]['id'];
			$s_map['id'] = $list[$i]['id'];
			$m_mall_content->where($s_map)->save($data);
			
		}
	} */
	
	
	/* 专辑数据 */
	/* public function zhuanji(){
		$m_common_user = M('common_user');   //用户表
		$m_mall_content = M('mall_content');   //用户表
		$m_mall_content_img = M('mall_content_img');   //用户表
		$style = array(778,880,799);
		
		for($i=6;$i<=5;$i++){
			$data['uid'] = getUID();
			$data['langue'] = 780;
			$data['style'] = '778,880,799';
			$data['name'] = '添加专辑'.$i;
			$data['singer'] = '歌手';
			$data['money'] = 10;
			$data['type'] = 16;
			$data['inventory'] = 100;
			$data['release_time'] = strtotime('2018-05-10');
			$data['img'] = "/upload/1/2018/05/10/5af39bf1d5ecd.png";
			$data['banner_img'] = "/upload/1/2018/05/10/5af39bf1d5ecd.png";
			$data['intro'] = "专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍专辑介绍";
			$data['status'] = 1;
			$result = $m_mall_content->add($data);
			add_style(2,$result,$style); 
			for($ii=0;$ii<=4;$ii++){
				$f_data['uid'] = getUID();
				$f_data['form_id'] = $result;
				$f_data['name'] = "歌曲".$ii;
				$f_data['langue'] = 780;
				$f_data['style'] = '778,880,799';
				$f_data['lyrics'] = '作词'.$ii;
				$f_data['compose'] = '作曲'.$ii;
				$f_data['arranged'] = '编曲'.$ii;
				$f_data['type'] = 17;
				$f_data['record'] = '录音'.$ii;
				$f_data['mixing'] = '混音'.$ii;
				$f_data['singer'] = '演唱者'.$ii;
				$f_data['producer'] = '制作人'.$ii;
				$f_data['producers'] = '出品方'.$ii;
				$f_data['value'] = '/upload/1/2018/05/10/5af3a15560a97.lrc';
				$f_data['mp3'] = '/upload/1/2018/05/10/5af3a1241bb07.mp3';
				$f_data['status'] = 1;
				
				$f_result = $m_mall_content->add($f_data);
				 #歌词本低衬页    宣传图
				for($iii=0;$iii<=3;$iii++){
					$form_data['type'] = 2;
					$form_data['uid'] = getUID();
					$form_data['form_id'] = $f_result;
					$form_data['time'] = time();
					$form_data['status'] = 1;
					$form_data['url'] = "/upload/1/2018/05/10/5af3a595ce762.png";
					$form_result = $m_mall_content_img->add($form_data);
					
					$xuanchuan['type'] = 3;
					$xuanchuan['uid'] = getUID();
					$xuanchuan['form_id'] = $f_result;
					$xuanchuan['time'] = time();
					$xuanchuan['status'] = 1;
					$xuanchuan['url'] = '/upload/1/2018/05/10/5af3a634a57e1.png';
					$xuanchuan_result = $m_mall_content_img->add($xuanchuan);
				}
			}	
		}
		
	} */
	
	
	
	/* PM排行banner */
	public function pm_banner(){
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		if(IS_POST){
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				
				#查询该偏好下的banner
				$banner_map['style_id'] = array('in',$user_style_str);
				$banner_map['style_table'] = 4;      //表示banner
				$banner_list = $m_cms_style->field('music_id')->where($banner_map)->select();
				
				#改为一维数组并且去重
				$banner_array = array_column($banner_list,'music_id');
				$banner_array = array_unique($banner_array);
				$banner_str = implode(',',$banner_array);
				#根据偏好查询出来的banner
				$banner_str_map['id'] = array('in',$banner_str);
			}
			$banner_str_map['status'] = 1;
			$banner_str_map['form_id'] = 172;            //首页
			$banner_str_map['type'] = get_cms_model_conf('CMS_BANNER');
			$banner_str_list = $m_cms_content->where($banner_str_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit(5)->select();
			foreach($banner_str_list as $i=>$v){
				
				$banner_str_list[$i]['img'] = if_url($banner_str_list[$i]['img']);
			}
			#总共5个banner图
			$banner_style_count = count($banner_str_list);
			
			#小于5时查询默认banner
			if($banner_style_count < 5){
				#查询剩下的默认banner图
				$banner_count = 5-$banner_style_count;
				$banner_cms_map['type'] = get_cms_model_conf('CMS_BANNER');
				$banner_cms_map['status'] = 1;
				$banner_cms_map['style_id'] = 0;
				$banner_cms_map['form_id'] = 172;            //首页
				$banner_cms_list = $m_cms_content->where($banner_cms_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit($banner_count)->select();
				foreach($banner_cms_list as $i=>$v){
					$banner_cms_list[$i]['img'] = if_url($banner_cms_list[$i]['img']);
				}
				foreach($banner_cms_list as $i=>$v){
					$banner_str_list[] = $banner_cms_list[$i];
				}
			}
			#img 图片 jump_type跳转类型(1活动页面，2专辑购买，3单曲试听)  jump_num 跳转页面id 
			
			
			#最终banner  $banner_str_list   排序后完成
			#排序
			$banner_str_list = banner_sorting($banner_str_list);
			
			$echo['error_code'] = 1;
			$echo['data'] = $banner_str_list;
			
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	/* 热门分类 */
	public function pm_style(){
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->field("img,name,id,intro")->order('pm_sort desc')->select();
			foreach($list as $i=>$v){
				$list[$i]['img'] = if_url($list[$i]['img']);
				$list[$i]['intro'] = if_url($list[$i]['intro']);
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	/* PM精选专辑 */
	public function pm_album(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_cms_style = M('cms_style');
		if(IS_POST){
			#默认条数，页数
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			
			#查询用户偏好
			$uid = I('param.uid');         //用户id
			$style = I('param.style');     //热门分类选择
			if($uid > 0){
				$user_style_str = user_style($uid);
				#查询该偏好下的推荐专辑
				$tuijian_map['style_id'] = array('in',$user_style_str);
				$tuijian_map['style_table'] = 2;      //表示专辑
				$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
				#改为一维数组并且去重
				$tuijian_array = array_column($tuijian_list,'music_id');
				$tuijian_array = array_unique($tuijian_array);
				$tuijian_str = implode(',',$tuijian_array);
				
				#根据偏好查询出来的专辑
				$tuijian_str_map['id'] = array('in',$tuijian_str);
			}
			#传分类时使用分类
			if($style > 0){
				$tuijian_str_map['style'] = array('like',"%$style%");
				unset($tuijian_str_map['id']);
			}
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_ALBUM');
			$tuijian_str_list = $m_mall_content->where($tuijian_str_map)->field("img,name,id,inventory,money")->order("pm_sort desc")->page($p,$page)->select();
			foreach($tuijian_str_list as $i=>$v){
				$tuijian_str_list[$i]['img'] = if_url($tuijian_str_list[$i]['img']);
			}
			#img封面图  name名称  id主键    inventory 库存  money价格
			$echo['error_code'] = 1;
			$echo['data'] = $tuijian_str_list;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
		
	}
	
	/* PM精选单曲*/
	public function pm_song(){
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		$m_mall_content_img = M('mall_content_img');
		$m_cms_style = M('cms_style');
		if(IS_POST){
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):4;
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			$style = I('param.style');   //风格  1527242662573
			if($uid > 0){
				$user_style_str = user_style($uid);
				#查询该偏好下的推荐专辑
				$tuijian_map['style_id'] = array('in',$user_style_str);
				$tuijian_map['style_table'] = 1;      //表示专辑
				$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
				#改为一维数组并且去重
				$tuijian_array = array_column($tuijian_list,'music_id');
				$tuijian_array = array_unique($tuijian_array);
				$tuijian_str = implode(',',$tuijian_array);
				
				#根据偏好查询出来的专辑
				$tuijian_str_map['id'] = array('in',$tuijian_str);
			}
			#传分类时使用分类
			if($style > 0){
				$tuijian_str_map['style'] = array('like',"%$style%");
				unset($tuijian_str_map['id']);
			}
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_SINGLE');
			$tuijian_str_list = $m_mall_content->where($tuijian_str_map)->field("name,singer,id")->order("pm_sort desc")->page($p,$page)->select();
			$tuijian_str_list = array_column($tuijian_str_list,'id');
			$tuijian_str_array = song_detail($tuijian_str_list,$uid);
			/* foreach($tuijian_str_list as $i=>$v){
				#判断是否是独家以及是否是超品
				$hq_dujia_array = if_hq_dujia($tuijian_str_list[$i]['id']);
				$tuijian_str_list[$i]['if_hq'] = $hq_dujia_array['if_hq'];
				$tuijian_str_list[$i]['if_dujia'] = $hq_dujia_array['if_dujia'];
				
				$xuanze_img_map['type'] = 1;					
				$xuanze_img_map['form_id'] = $tuijian_str_list[$i]['id'];
				$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
				$tuijian_str_list[$i]['img'] = if_url($xuanze_img_data['url']);
			} */
			
			#img封面图  singer 歌手 id主键   name名称
			$echo['error_code'] = 1;
			$echo['data'] = $tuijian_str_array;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
		
	}
	
	
	/* 搜索 */
	public function search(){
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		if(IS_POST){
			
			$name = I("param.name");
			$uid = I("param.uid");
			if($name == ''){
				
			}else{
				#搜索专辑
				$album_map['name'] = array("like","%$name%");
				$album_map['type'] = 16;
				$album_map['status'] = 1;
				$album_list = $m_mall_content->where($album_map)->field("img,id,name,singer")->select();
				foreach($album_list as $i=>$v){
					$album_list[$i]['img'] = if_url($album_list[$i]['img']);
				}
				#搜索音乐人
				$user_map['nickname'] = array("like","%$name%");
				$user_map['group_id'] = 9;
				$user_map['status'] = 1;
				$user_list = $m_common_user->where($user_map)->field("nickname,id,img")->select();
				foreach($user_list as $i=>$v){
					#判断是否是授权   授权的头像了路径不改变
					$user_list[$i]['img'] = if_url($user_list[$i]['img'] );
				}
				#搜索歌曲
				$song_map['name'] = array("like","%$name%");
				$song_map['type'] = 15;
				$song_map['status'] = 1;
				$song_list = $m_mall_content->where($song_map)->field("id,name,singer")->select();
				$song_list = array_column($song_list,'id');
				$song_list_array = song_detail($song_list,$uid);
				/* foreach($song_list as $i=>$v){
					
					#判断是否是独家以及是否是超品
					$hq_dujia_array = if_hq_dujia($song_list[$i]['id']);
					$song_list[$i]['if_hq'] = $hq_dujia_array['if_hq'];
					$song_list[$i]['if_dujia'] = $hq_dujia_array['if_dujia'];
					
					$xuanze_img_map['type'] = 1;					
					$xuanze_img_map['form_id'] = $song_list[$i]['id'];
					$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
					$song_list[$i]['img'] = $xuanze_img_data['url'];
				} */
			}
			
			$echo_list['album'] = $album_list;
			$echo_list['user'] = $user_list;
			$echo_list['song'] = $song_list_array;
			
			$echo['error_code'] = 1;
			$echo['data'] = $echo_list;
			#dump($echo);die;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}else{
			$echo['error_code'] = 0;
			$echo_str = json_encode($echo);
			echo $echo_str;
		}
		
	}
	
	/* 发现首页 */
	public function found_banner(){
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_cms_content = M('cms_content');   //banner
		if(IS_POST){
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			if($uid > 0){
				$user_style_str = user_style($uid);
				
				#查询该偏好下的banner
				$banner_map['style_id'] = array('in',$user_style_str);
				$banner_map['style_table'] = 4;      //表示banner
				$banner_list = $m_cms_style->field('music_id')->where($banner_map)->select();
				
				#改为一维数组并且去重
				$banner_array = array_column($banner_list,'music_id');
				$banner_array = array_unique($banner_array);
				
				$banner_str = implode(',',$banner_array);
				
				#根据偏好查询出来的banner
				
				$banner_str_map['id'] = array('in',$banner_str);
			}
			$banner_str_map['status'] = 1;
			$banner_str_map['form_id'] = 178;            //首页
			$banner_str_map['type'] = get_cms_model_conf('CMS_BANNER');
			$banner_str_list = $m_cms_content->where($banner_str_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit(5)->select();
			foreach($banner_str_list as $i=>$v){
				$banner_str_list[$i]['img'] = if_url($banner_str_list[$i]['img']);
			}
			#总共5个banner图
			$banner_style_count = count($banner_str_list);
			
			#小于5时查询默认banner
			if($banner_style_count < 5){
				#查询剩下的默认banner图
				$banner_count = 5-$banner_style_count;
				
				$banner_cms_map['type'] = get_cms_model_conf('CMS_BANNER');
				$banner_cms_map['status'] = 1;
				$banner_cms_map['style_id'] = 0;
				$banner_cms_map['form_id'] = 178;            //首页
				$banner_cms_list = $m_cms_content->where($banner_cms_map)->field("img,jump_type,jump_num,sort")->order("sort desc")->limit($banner_count)->select();
				foreach($banner_cms_list as $i=>$v){
					$banner_cms_list[$i]['img'] = if_url($banner_cms_list[$i]['img']);
				}
				foreach($banner_cms_list as $i=>$v){
					$banner_str_list[] = $banner_cms_list[$i];
				}
			}
			#img 图片 jump_type跳转类型(1活动页面，2专辑购买，3单曲试听)  jump_num 跳转页面id 
			
			#最终banner  $banner_str_list   排序后完成
			#排序
			$banner_str_list = banner_sorting($banner_str_list);
			
			$echo['error_code'] = 1;
			$echo['data'] = $banner_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	
	/* 精选歌单 */
	public function select_playlist(){
		$m_common_user = M('common_user');   //用户表
		$m_cms_style = M('cms_style');   //用户偏好表
		$m_mall_content = M('mall_content');   //用户偏好表
		$m_cms_recently = M('cms_recently');   //用户偏好表
		if(IS_POST){
			
			#查询用户偏好
			$uid = I('param.uid');   //用户id
			#$uid = 1;   //用户id
			if($uid > 0 ){
				$user_style_str = user_style($uid);
				$playlist_map['style_id'] = array('in',$user_style_str);
				$playlist_map['style_table'] = 6;      //表示banner
				$playlist_list = $m_cms_style->field('music_id')->where($playlist_map)->select();
				
				#改为一维数组并且去重
				$playlist_array = array_column($playlist_list,'music_id');
				$playlist_array = array_unique($playlist_array);
				
				$playlist_str = implode(',',$playlist_array);
				
				#根据偏好查询出来的banner
				
				$playlist_str_map['id'] = array('in',$playlist_str);
			}
			
			$playlist_str_map['status'] = 1;
			$playlist_str_map['recommended'] = 1;
			$playlist_str_map['type'] = get_mall_model_conf('MALL_PLAYLIST');
			$playlist_str_list = $m_mall_content->where($playlist_str_map)->field("name,img,id")->order("pm_sort desc")->limit(6)->select();
			
			foreach($playlist_str_list as $i=>$v){
				$playlist_str_list[$i]['img'] = if_url($playlist_str_list[$i]['img']);
				$recently_map['type'] = 5;
				$recently_map['r_id'] = $playlist_str_list[$i]['id'];
				$playlist_str_list[$i]['count'] = $m_cms_recently->where($recently_map)->count("count");
			}
			$echo['error_code'] = 1;
			$echo['data'] = $playlist_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	/* 发现中分类 */
		public function found_style(){
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->select();
			foreach($list as $i=>$v){
				$list[$i]['img'] = if_url($list[$i]['img']);
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	
	/* 发现中的分类下歌单 */
	public function found_playlist(){
		
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_cms_recently = M("cms_recently");
		if(IS_POST){
			#第一个默认偏好风格
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->limit(1)->find();
			$data['img'] = if_url($data['img']);
			$style_id = I("param.style_id")?I("param.style_id"):$data['id'];
			
			#查询偏好风格下的歌单
			$tuijian_map['style_id'] = $style_id;
			$tuijian_map['style_table'] = 6;      //表示歌单
			$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
			
			#改为一维数组并且去重
			$tuijian_array = array_column($tuijian_list,'music_id');
			$tuijian_array = array_unique($tuijian_array);
			
			$tuijian_str = implode(',',$tuijian_array);
			
			#该风格下的歌单
			$tuijian_str_map['id'] = array('in',$tuijian_str);
			$tuijian_str_map['status'] = 1;
			$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = get_mall_model_conf('MALL_PLAYLIST');
			$playlist_str_list = $m_mall_content->where($tuijian_str_map)->field("name,img,id")->order("pm_sort desc")->limit(60)->select();
			
			foreach($playlist_str_list as $i=>$v){
				$playlist_str_list[$i]['img'] = if_url($playlist_str_list[$i]['img']);
				$recently_map['type'] = 5;
				$recently_map['r_id'] = $playlist_str_list[$i]['id'];
				$playlist_str_list[$i]['count'] = $m_cms_recently->where($recently_map)->count("count");
			}
			$echo['error_code'] = 1;
			$echo['data'] = $playlist_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	
	/* 发现中的音乐人 */
	public function music_user(){
		$m_common_user_country = M("common_user_country");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		if(IS_POST){
			#地区
			$country_lists = $m_common_user_country->order("id asc")->select();
			$country_list[0]['id'] = 0;
			$country_list[0]['name'] = "全部";
			
			$country_list = array_merge($country_list,$country_lists);
			
			#男女  组合
			$sex = array(array("id"=>"0",'name'=>'全部'),array("id"=>"1",'name'=>'男'),array("id"=>"2",'name'=>'女'),array("id"=>"3",'name'=>'组合'));
			
			#分类
			$style_maps['type'] = get_mall_model_conf('MALL_STYLE');
			$style_maps['status'] = 1;
			$style_lists = $m_mall_content->where($style_maps)->field("id,name")->order('sort desc')->select();
			
			$style_list[0]['id'] = 0;
			$style_list[0]['name'] = "全部";
			
			$style_list = array_merge($style_list,$style_lists);
			
			#音乐人热门
			$user_map['status'] = 1;
			$user_map['group_id'] = 9;
			$user_list = $m_common_user->where($user_map)->field("id,name,img,fans")->order("fans desc")->limit(20)->select();
			foreach($user_list as $i=>$v){
				#判断是否是授权   授权的头像了路径不改变
				
				$user_list[$i]['img'] = if_url($user_list[$i]['img']);
			}
			$echo_array['country'] = $country_list;
			$echo_array['sex'] = $sex;
			$echo_array['style'] = $style_list;
			$echo_array['user'] = $user_list;
			
			$echo['error_code'] = 1;
			$echo['data'] = $echo_array;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo; 
		}
	}
	
	/* 发现中的音乐人搜索 */
	public function seach_music_user(){
		$m_common_user = M("common_user");
		$m_cms_collection = M("cms_collection");
		if(IS_POST){
			#音乐人热门
			$uid = I('param.uid')?I('param.uid'):0;  
			#dump($uid);die;
			$country = I('param.country');
			$sex = I('param.sex');
			$style = I('param.style');
			
			if($country > 0){
				$user_map['country'] = $country;
			}
			if($sex > 0){
				$user_map['sex'] = $sex;
			}
			if($style > 0){
				$user_map['style'] = array('like',"%$style%");
			}
			
			$user_map['status'] = 1;
			$user_map['group_id'] = 9;
			$user_list = $m_common_user->where($user_map)->field("id,name,img,fans")->order("cz_sort desc")->limit(20)->select();
			foreach($user_list as $i=>$v){
				#判断是否是授权   授权的头像了路径不改变
					$user_list[$i]['img'] = if_url($user_list[$i]['img']);
				
				#判断是否喜欢
				$if_map['uid'] = $uid;
				$if_map['form_id'] = $user_list[$i]['id'];
				$if_map['type'] = 2;
				$if_data = $m_cms_collection->where($if_map)->field("id")->find();
				if($if_data){
					$user_list[$i]['if_like'] = 1;
				}else{
					$user_list[$i]['if_like'] = 0;
				}
				
			}
			$echo['error_code'] = 1;
			$echo['data'] = $user_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	
	/* 音乐人详情 */
	public function music_user_details(){
		$m_common_user = M("common_user"); 
		$m_mall_content = M("mall_content");
		$m_cms_collection = M("cms_collection");
		$m_cms_recently = M("cms_recently");
		$m_mall_content_img = M("mall_content_img");
		
		if(IS_POST){
			$id = I('param.id');
			$uid = I('param.uid');
			#$id = 1;
			if($id > 0){
				$map['id'] = $id;
				$map['status'] = 1;
				$map['group_id'] = 9;
				$user_data = $m_common_user->where($map)->field("id,nickname,img,fans,votes,intro")->find();
				$user_data['votes_num'] = jindu_num($user_data['votes']);
				
				$user_data['img'] = if_url($user_data['img']);
				
				#专辑
				$album_map['uid'] = $id;
				$album_map['status'] = 1;
				$album_map['type'] = 16;
				$album_list = $m_mall_content->where($album_map)->field("img,name,id")->select();
				foreach($album_list as $i=>$v){
					$album_list[$i]['img'] = if_url($album_list[$i]['img']);
				}
				foreach($album_list as $i=>$v){
					$songs_map['form_id'] = $album_list[$i]['id'];
					$songs_map['type'] = 17;
					$songs_map['status'] = 1;
					$album_list[$i]['songs_count'] = $m_mall_content->where($songs_map)->count();
				}
				
				#活动
				$activity_map['uid'] = $id;
				$activity_map['status'] = 1;
				$activity_map['type'] = 19;
				$activity_list = $m_mall_content->where($activity_map)->field("img,id")->select();
				foreach($activity_list as $i=>$v){
					$activity_list[$i]['img'] = if_url($activity_list[$i]['img']);
				}
				#粉丝圈
				$fans_map['form_id'] = $id;
				$fans_map['type'] = 2;
				$fans_list = $m_cms_collection->where($fans_map)->field("uid,time")->select();
				
				foreach($fans_list as $i=>$v){
					$f_user['id'] = $fans_list[$i]['uid'];
					$f_data = $m_common_user->where($f_user)->field("id,nickname,img,intro")->find();
					#判断是否是授权   授权的头像了路径不改变
					$f_data['img'] = if_url($f_data['img']);
					
					$time = date("Y-m-d H:i",$fans_list[$i]['time']);
					$fans_list[$i] = $f_data;
					$fans_list[$i]['time'] = $time;
				}
				
				
				#单曲
				$song_map['uid'] = $id;
				$song_map['status'] = 1;
				$song_map['type'] = 15;
				$song_list = $m_mall_content->where($song_map)->field("id,name,singer")->select();
				#改为一维数组并且去重
				$song_array = array_column($song_list,'id');
				$song_array = array_unique($song_array);
				$song_lists = song_detail($song_array,$uid);
				/* foreach($song_list as $i=>$v){
					#收听量
					$ting_map['type'] = 2;
					$ting_map['r_id'] = $song_list[$i]['id'];
					$song_list[$i]['count'] = $m_cms_recently->where($ting_map)->sum("count");
					
					$xuanze_img_map['type'] = 1;					
					$xuanze_img_map['form_id'] = $song_list[$i]['id'];
					$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
					$song_list[$i]['img'] =  if_url($xuanze_img_data['url']);
				} */
				
				$if_map['uid'] = $uid;
				$if_map['form_id'] = $id;
				$if_map['type'] = 2;
				$if_data = $m_cms_collection->where($if_map)->field("id")->find();
				if($if_data){
					$user_data['if_like'] = 1;
				}else{
					$user_data['if_like'] = 0;
				}
				
				
				$echo_array['user_data'] = $user_data;
				$echo_array['album'] = $album_list;
				$echo_array['activity'] = $activity_list;
				$echo_array['fans'] = $fans_list;
				$echo_array['song'] = $song_lists;
			}
			$echo['error_code'] = 1;
			$echo['data'] = $echo_array;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	/* 我的页面   我发布的活动 */
	public function my_activity(){
		
		$m_mall_content = M("mall_content");
		$m_mall_order = M("mall_order");
		if(IS_POST){
			$uid = I('param.uid');
			#$uid = 1;
			if($uid > 0){
				#我发布的活动 
				$my_activity['type'] = 19;
				$my_activity['status'] = 1;
				$my_activity['uid'] = 1;
				$my_activity_list = $m_mall_content->where($my_activity)->field("id,name,release_time,address,style,img")->select();
				
				foreach($my_activity_list as $i=>$v){
					$my_activity_list[$i]['img'] = if_url($my_activity_list[$i]['img']);
					$my_activity_list[$i]['style'] = style_str(($my_activity_list[$i]['style']));
					$my_activity_list[$i]['release_time'] = date("Y-m-d H:i",$my_activity_list[$i]['release_time']);	
				}
				#dump($my_activity_list);die;
				
				#我购买的活动
				
				/* #查询我的所有商品id
				$order_map['uid'] = $uid;
				$order_map['order_type'] = 3;
				$order_map['status'] = 1;
				$order_list = $m_mall_order->where($order_map)->field("id,goods_id")->order("time desc")->select();
				#改为一维数组并且去重
				$order_array = array_column($order_list,'goods_id');
				$order_array = array_unique($order_array);
				
				foreach($order_array as $i=>$v){
					$activity_map['id'] = $order_array[$i];
					$activity_data = $m_mall_content->where($activity_map)->field("name,release_time,address,style,img")->find();
					$activity_data['img'] = "http://".$_SERVER['HTTP_HOST'].$activity_data['img'];
					$activity_data['time'] = date("Y-m-d H:i",$activity_data['release_time']);
					$activity_data['style'] = style_str($activity_data['style']);
					$activity_data['order_id'] = $order_list[$i]['id'];
					$activity_list[] = $activity_data;
				} */
				
			}
			$echo['error_code'] = 1; 
			$echo['data'] = $my_activity_list; 
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	#我的偏好设置
	public function my_style_save(){
		
		if(IS_POST){
			$uid = I('param.uid');
			#$uid = 46;
			if($uid > 0){
				$user_style_str = user_style($uid);   //用户风格
			}else{
				$user_style_str = array();
			}
			$style_list = gettypes();            //所有风格
			$list = if_style($style_list,$user_style_str);
			
			$list = banner_sorting($list);
			
			
			$echo['error_code'] = 1; 
			$echo['data'] = $list; 
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
		
	}
	
	#我的PM票
	public function my_pm_ticket(){
		$m_common_user_votes = M("common_user_votes");
		$m_common_user = M("common_user");
		if(IS_POST){
			$uid = I('param.uid');
			#$uid = 1;
			if($uid > 0){
				$user_map['user_id'] = $uid;
				$user_map['status'] = 1;
				$list = $m_common_user_votes->where($user_map)->field("music_id")->order("time desc")->select();
				
				foreach($list as $i=>$v){
					$users_map['id'] = $list[$i]['music_id'];
					$users_map['group_id'] = 9;
					$users_map['status'] = 1;
					$user_data = $m_common_user->where($users_map)->field("id,nickname,img,fans")->order("fans desc")->find();
					#判断是否是授权   授权的头像了路径不改变
					$user_data['img'] = if_url($user_data['img']);
					
					$list_array[] = $user_data; 
				}
			
			}
			$echo['error_code'] = 1; 
			$echo['data'] = $list_array; 
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0; 
			echo json_encode($echo);
		}
	}
		
	#微信授权 openid     nickName  gender  性别   avatarUrl  头像
	public function weixin_add(){
		$m_common_user = M("common_user");
		if(IS_POST){
			
			$user_map['weixin_openid'] = I('param.openid');
			$user_name = $m_common_user->where($user_map)->find();
			if($user_name){
				$info = $user_name['id'];
			}else{
				$user_map['username'] = I('param.openid');
				$user_map['weixin_openid'] = I('param.openid');
				$user_map['nickname'] = I('param.nickname');
				$user_map['sex'] = I('param.gender');
				$user_map['img'] = I('param.avatarUrl');
				$user_map['group_id'] = 3;
				$user_map['create_time'] = time();
				$user_map['ip'] = get_client_ip();
				$user_map['status'] = 1;
				$result = $m_common_user->add($user_map);
				$info = $result;
			}
			$echo['error_code'] = 1;
		}else{
			$info = 0;
			$echo['error_code'] = 0;
		}
		
		$echo['data'] = $info;
		echo json_encode($echo);
	}
	
	#我关注的音乐人
	public function my_guanzhu(){
		$m_cms_collection = M("cms_collection");
		$m_common_user = M("common_user");
		
		if(IS_POST){
			
			$uid = I("param.uid");
			#$uid = 1;
			if($uid > 0){
				$map['uid'] = $uid;
				$map['type'] = 2;
				$list = $m_cms_collection->where($map)->field('form_id')->select();
				foreach($list as $i=>$v){
					$user_map['status'] = 1;
					$user_map['group_id'] = 9;
					$user_map['id'] = $list[$i]['form_id'];
					$user_data = $m_common_user->where($user_map)->field("id,nickname,img,fans")->find();
					if($user_data){
						#判断是否是授权   授权的头像了路径不改变
						$user_data['img'] = if_url($user_data['img']);
					
						$user_list[] = $user_data;
					}
					
				}
				
			}else{
					
			}
			$echo['error_code'] = 1;
			$echo['data'] = $user_list;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	
	#音乐人根据单曲播放量排行
	public function play_count(){
		$m_common_user = M("common_user");
		$m_cms_recentlys = M("cms_recentlys");
		$m_mall_content = M("mall_content");
		
		if(IS_POST){
		#插入风格
		#$style_id
		
		$user_map['status'] = 1;
		$user_map['group_id'] = 9;
		$user_list = $m_common_user->where($user_map)->field('id')->select();
		foreach($user_list as $i=>$v){
			$counts = 0;
			$song_map['uid'] = $user_list[$i]['id'];
			$song_map['type'] = 15;
			$song_map['status'] = 1;
			$song_list = $m_mall_content->where($song_map)->field("id")->select();
			foreach($song_list as $ii=>$vv){
				$tongji_map['type'] = 2;
				$tongji_map['r_id'] = $song_list[$ii]['id'];
				#插入时间范围
				$count = $m_cms_recentlys->where($tongji_map)->field("id")->count();
				$counts = $count+$counts;
			}
			$user_list[$i]['sort'] = $counts;
		}
		
		$user_list = banner_sorting($user_list);
		#查询音乐人详情
		foreach($user_list as $i=>$v){
			$result = $m_common_user->where($user_map)->field('nickname,img')->find();
			$user_list[$i]['nickname'] = $result['nickname'];
			
			#判断是否是授权   授权的头像了路径不改变
			$user_list[$i]['img'] = if_url($user_list[$i]['img']);
		}
		
			
			$echo['error_code'] = 1;
			$echo['data'] = $user_list;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			#$echo['data'] = $user_list;
			echo json_encode($echo);
		}
	}
	
	#专辑销量的专辑排行
	public function album_sales(){
		$m_mall_content = M("mall_content");
		if(IS_POST){
			$style = I("param.style");
			$map['type'] = 16;
			$map['status'] = 1;
			#插入时间
			#$map['time'] = array();
			
			#插入风格
			if($style > 0){
				$map['style'] = array("like","%$style%");
			}
			$list = $m_mall_content->where($map)->field("id,name,img,sale,intro")->order("sale desc")->limit(10)->select();
			
			foreach($list as $i=>$v){
				$list[$i]['img'] = if_url($list[$i]['img']);
				$list[$i]['sale_sum'] = jindu_num($list[$i]['sale']);
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
		
		
	}
	
	
	#音乐人热度排行
	public function music_people(){
		
		$m_common_user = M("common_user");
		$m_common_user_votes = M("common_user_votes");
		if(IS_POST){
			$style = I('param.style'); 
			$user_map['status'] = 1;
			$user_map['group_id'] = 9;
			#插入风格
			if($style > 0){
				$user_map['style'] = array("like","%$style%");
			}
			$user_list = $m_common_user->where($user_map)->field("id,nickname,img")->select();
			
			foreach($user_list as $i=>$v){
				#判断是否是授权   授权的头像了路径不改变
				$user_list[$i]['img'] = if_url($user_list[$i]['img']);
				$vote_map['music_id'] = $user_list[$i]['id'];
				$vote_map['status'] = 1;
				#插入时间
				$user_list[$i]['sort'] = $m_common_user_votes->where($vote_map)->sum("number");
				$user_list[$i]['votes_num'] = jindu_num($user_list[$i]['sort']);
				
			}
			$user_list = banner_sorting($user_list);
			$echo['error_code'] = 1;
			$echo['data'] = $user_list;
			#dump($echo);die;
			echo json_encode($echo);
		}else{
			$echo['error_code'] = 0;
			echo json_encode($echo);
		}
	}
	
	#余额支付  专辑
	# -6参数错误 -5请求错误 -4表示已经有了该专辑  -2 表示售完   -1 余额不足 -3结算失败 请重新结算  1 成功
	public function pay_balance(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		$m_cms_style = M("cms_style");
		$m_mall_money = M("mall_money");
		
		 if(IS_POST){
			
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			
			$user_map['id'] = $uid;
			$user_data = $m_common_user->where($user_map)->find();
			
			#商品详情
			$goods_map['id'] = $goods_id;
			$goods_map['type'] = array('in','16,22');
			$goods_map['status'] = array('in','1');
			$goods_data = $m_mall_content->where($goods_map)->find();
			
			$goods_user_map['id'] = $goods_data['uid'];
			$goods_user_data = $m_common_user->where($goods_user_map)->find();
			
			if(!empty($user_data) and !empty($goods_data)){
				#判断类型   专辑   二手专辑
				if($goods_data['type'] == 16){
					$order_type = 1;
					$order_status = 5;
				}elseif($goods_data['type'] == 22){
					$order_type = 2;
					$order_status = 3;
				}
				
				#查询是否购买
				$if_goods_map['isrc'] = $goods_data['isrc'];
				$if_goods_map['uid'] = $uid;
				$if_goods_data = $m_mall_content->where($if_goods_map)->field('id')->find();
				if($if_goods_data['id'] > 0){
					$info = -4;
				}else{
					if($goods_data['inventory'] > 0){
						
						#扣余额
						if($goods_data['money'] <= $user_data['money']){
							#生成订单
							$map['today'] = getToday();
							$num = $m_mall_order->where($map)->count();
							
							$order_data['uid'] = $uid;
							$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
							$order_data['name'] = $goods_data['name'];
							$order_data['pay_type'] = 3;
							$order_data['money'] = $goods_data['money'];
							$order_data['goods_id'] = $goods_data['id'];
							$order_data['goods_img'] = $goods_data['img'];
							$order_data['goods_num'] = 1;
							$order_data['goods_money'] = $goods_data['money'];
							$order_data['tel'] = $user_data['tel'];
							$order_data['time'] = time();
							$order_data['today'] = getToday();
							$order_data['ip'] = get_client_ip();
							$order_data['order_type'] = $order_type;
							$order_data['status'] = 2;     //未支付
							$order_data['spending'] = 1;     //支出
							$result = $m_mall_order->add($order_data);
							
							#给买方减少余额
							$money_result = $m_common_user->where($user_map)->setDec("money",$goods_data['money']);
							$money_results = $m_common_user->where($user_map)->setInc("integral",$goods_data['money']);   //pm票
							
							if($money_result){
							
								$nums = $m_pay_order->where($map)->count();
								$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
								$form_order_map['order_id'] = $order_id;
								$form_order_map['name'] = $goods_data['name'];
								$form_order_map['money'] = $goods_data['money'];
								$form_order_map['type'] = 3;
								$form_order_map['time'] = time();
								$form_order_map['ip'] = get_client_ip();
								$form_order_map['success_time'] = time();
								$form_order_map['success_ip'] = get_client_ip();
								$form_order_map['today'] =  getToday();
								$form_order_map['status'] =  1;
								$order_result = $m_pay_order->add($form_order_map);
								
								$save_order['id'] = $result;
								$save_data['form_order_id'] = $order_id;
								$save_data['status'] = 1;
								$m_mall_order->where($save_order)->save($save_data);
								
								#支付成功，给该专辑做库存处理，
								$m_mall_content->where($goods_map)->setInc("sale");
								$m_mall_content->where($goods_map)->setDec("inventory");
								
								#查询库存 若为1 卖出后为0 则修改商品状态
								if($goods_data['inventory'] <= 1){
									$order_status_data['status'] = $order_status;
									$m_mall_content->where($goods_map)->save($order_status_data);
								}
								
								
								#给卖方增加余额
								$mai_user_map['id'] = $goods_data['uid'];
								$m_common_user->where($mai_user_map)->setInc("money",$goods_data['money']);
								
								#买方支出记录
								$mall_money_data['uid'] = $user_data['id'];
								$mall_money_data['type'] = 2;
								$mall_money_data['order_type'] = 3;
								$mall_money_data['type_value'] = "余额购买专辑";
								$mall_money_data['begin_money'] = $user_data['money'];
								$mall_money_data['money'] = $goods_data['money'];
								$mall_money_data['end_money'] = $user_data['money'] - $goods_data['money'];
								$mall_money_data['value'] = $order_data['order_id'];
								$mall_money_data['time'] = time();
								$mall_money_data['ip'] = get_client_ip();
								$mall_money_data['status'] = 1;
								$res = $m_mall_money->add($mall_money_data);
								
								#卖放收入记录
								$mall_money_data['uid'] = $goods_data['uid'];
								$mall_money_data['type'] = 1;
								$mall_money_data['order_type'] = 3;
								$mall_money_data['type_value'] = "卖出专辑";
								$mall_money_data['begin_money'] = $goods_user_data['money'];
								$mall_money_data['money'] = $goods_data['money'];
								$mall_money_data['end_money'] = $goods_user_data['money'] + $goods_data['money'];
								$mall_money_data['value'] = $order_data['order_id'];
								$mall_money_data['time'] = time();
								$mall_money_data['ip'] = get_client_ip();
								$mall_money_data['status'] = 1;
								$res = $m_mall_money->add($mall_money_data);
								
								
								#生成我的专辑处理
								$goods_data['uid'] = $uid;
								$goods_data['type'] = 22;
								$goods_data['time'] = time();
								$goods_data['inventory'] = 1;
								$goods_data['original_money'] = $goods_data['money'];
								$goods_data['sale'] = 0;
								$goods_data['status'] = 2;
								unset($goods_data['id']);
								$my_goods_result = $m_mall_content->add($goods_data);
								
								#创建风格关联
								$add_style_array = explode(',',$goods_data['style']);
								
								foreach($add_style_array as $i=>$v){
									if($add_style_array[$i]){
										$add_style_app['style_id'] = $add_style_array[$i];
										$add_style_app['style_table'] = 2;
										$add_style_app['music_id'] = $my_goods_result;
										$m_cms_style->add($add_style_app);
									}
								}
								
								#查询专辑下歌曲
								$my_goods_song['form_id'] = $goods_map['id'];
								$my_goods_song['type'] = 17;
								$my_goods_song['status'] = 1;
								$my_goods_list = $m_mall_content->where($my_goods_song)->select();
								#dump($my_goods_list);die;
								foreach($my_goods_list as $i=>$v){
									#查询歌曲图片并且重新添加
									$my_img_map['type'] = array("in",'2,3');
									$my_img_map['status'] = 1;
									$my_img_map['form_id'] = $my_goods_list[$i]['id'];
									$my_img_list = $m_mall_content_img->where($my_img_map)->select();
									
									$my_goods_list[$i]['form_id'] = $my_goods_result;
									unset($my_goods_list[$i]['id']);
									
									$my_img_result = $m_mall_content->add($my_goods_list[$i]);
									
									foreach($my_img_list as $ii=>$vv){
										unset($my_img_list[$ii]['id']);
										$my_img_list[$ii]['form_id'] = $my_img_result;
										$m_mall_content_img->add($my_img_list[$ii]);
									}
								}
								$info = 1;
							}else{
								
								$info = -3;
							}
						}else{
							$info = -1;
						}
						
						
					}else{
						$info = -2;
					}
				
				}
				
			}else{
				$info = -6;
			}
			$echo['error_code'] = 1;
			$echo['data'] = $info;
		}else{
			$info = -5;
			$echo['error_code'] = 0;
			$echo['data'] = $info;
		}
		echo json_encode($echo);
	}
	
	#获取用户余额
	public function query_money(){
		$m_common_user = M("common_user");
		
		if(IS_POST){
			$uid = I("param.uid");
			#$uid = 1;
			if($uid > 0){
				$map['id'] = $uid;
				$result = $m_common_user->where($map)->field("money")->find();
				$money =  $result['money'];
			}else{
				$money = -1;
			}
			
			
			$echo['error_code'] = 1;
			$echo['data'] = $money;
		}else{
			$echo['error_code'] = 0;
		}
		echo json_encode($echo);
	}
	
	
	
	public function weixin_pay(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		
		 if(IS_POST){
			
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			
			$user_map['id'] = $uid;
			$user_data = $m_common_user->where($user_map)->find();
			
			#商品详情
			$goods_map['id'] = $goods_id;
			$goods_map['type'] = array('in','16,22');
			$goods_map['status'] = array('in','1,2');
			$goods_data = $m_mall_content->where($goods_map)->find();
			
			$goods_user_map['id'] = $goods_data['uid'];
			$goods_user_data = $m_common_user->where($goods_user_map)->find();
			
			
			if(!empty($user_data) and !empty($goods_data)){
				#判断类型   专辑   二手专辑
				if($goods_data['type'] == 16){
					$order_type = 1;
				}elseif($goods_data['type'] == 22){
					$order_type = 2;
				}
				
				#查询是否已购买
				$if_goods_map['isrc'] = $goods_data['isrc'];
				$if_goods_map['uid'] = $uid;
				$if_goods_data = $m_mall_content->where($if_goods_map)->field('id')->find();
				#dump($if_goods_data);die;
				if($if_goods_data['id'] > 0){
					$info = -4;
				}else{
					if($goods_data['inventory'] > 0){
							#生成订单
							$map['today'] = getToday();
							$num = $m_mall_order->where($map)->count();
							
							$order_data['uid'] = $uid;
							$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
							$order_data['name'] = $goods_data['name'];
							$order_data['pay_type'] = 2;
							$order_data['money'] = $goods_data['money'];
							$order_data['goods_id'] = $goods_data['id'];
							$order_data['goods_img'] = $goods_data['img'];
							$order_data['goods_num'] = 1;
							$order_data['goods_money'] = $goods_data['money'];
							$order_data['tel'] = $user_data['tel'];
							$order_data['time'] = time();
							$order_data['today'] = getToday();
							$order_data['ip'] = get_client_ip();
							$order_data['order_type'] = $order_type;
							$order_data['status'] = 2;     //未支付
							$result = $m_mall_order->add($order_data);
							
							if($result){
								
								$nums = $m_pay_order->where($map)->count();
								$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
								$form_order_map['order_id'] = $order_id;
								$form_order_map['name'] = $goods_data['name'];
								$form_order_map['money'] = $goods_data['money'];
								$form_order_map['type'] = 2;
								$form_order_map['time'] = time();
								$form_order_map['ip'] = get_client_ip();
								$form_order_map['success_time'] = time();
								$form_order_map['success_ip'] = get_client_ip();
								$form_order_map['today'] =  getToday();
								$form_order_map['status'] = 2;
								$order_result = $m_pay_order->add($form_order_map);
								
								$save_order['id'] = $result;
								$save_data['form_order_id'] = $order_id;
								$m_mall_order->where($save_order)->save($save_data);
								
								$array_pay['openid'] = $user_data['weixin_openid'];
								$array_pay['body'] = $goods_user_data['nickname']."-".$goods_data['name'];
								$array_pay['order_sn'] = $order_id;
								$array_pay['total_fee'] = $goods_data['money'];    //单位为分
								$info = 1;
							}else{
								$info = -3;
							}
						
					}else{
						$info = -2;
					}
				}
				
			}else{
				$info = -6;
			}
			$echo['error_code'] = $info;
			$echo['data'] = $array_pay;
		}else{
			$info = -5;
			$echo['error_code'] = $info;
		}
		#dump($echo);die;
		$echo = json_encode($echo);
		echo $echo;
		
	}
	
	#微信支付 活动   -4 已经购买 -6 商品不存在  -5 请求错误   -2 票已售罄   1 成功
	public function weixin_pay_activity(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		$m_mall_content_money = M("mall_content_money");
		
		 if(IS_POST){
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			$goods_type_id = I("param.goods_type_id");
			
			$user_map['id'] = $uid;
			$user_data = $m_common_user->where($user_map)->find();
			
			#商品详情
			$goods_map['id'] = $goods_id;
			$goods_map['type'] = 19;
			$goods_map['status'] = 1;
			$goods_data = $m_mall_content->where($goods_map)->find();
			
			$goods_user_map['id'] = $goods_data['uid'];
			$goods_user_data = $m_common_user->where($goods_user_map)->find();
			
			if(!empty($goods_data)){
				#判断类型 活动
				$order_type = 3;
				#查询是否已购买
				$if_goods_map['goods_id'] = $goods_id;
				$if_goods_map['uid'] = $uid;
				$if_goods_map['status'] = 1;
				$if_goods_data = $m_mall_order->where($if_goods_map)->field('id')->find();
				if($if_goods_data['id'] > 0){
					$info = -4;      //已经购买
				}else{
					$goods_m_map['id'] = $goods_type_id;
					$goods_m_map['goods_id'] = $goods_id;
					$goods_m_data = $m_mall_content_money->where($goods_m_map)->find();
					#dump($goods_m_data);die;
					if($goods_m_data['number'] > 0){
							#生成订单
							$map['today'] = getToday();
							$num = $m_mall_order->where($map)->count();
							
							$order_data['uid'] = $uid;
							$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
							$order_data['name'] = $goods_data['name'];
							$order_data['pay_type'] = 2;
							$order_data['money'] = $goods_m_data['goods_money'];
							$order_data['goods_id'] = $goods_data['id'];
							$order_data['goods_img'] = $goods_data['img'];
							$order_data['goods_num'] = 1;
							$order_data['goods_money'] = $goods_m_data['goods_money'];
							$order_data['goods_type_id'] = $goods_type_id;
							$order_data['tel'] = $user_data['tel'];
							$order_data['time'] = time();
							$order_data['today'] = getToday();
							$order_data['ip'] = get_client_ip();
							$order_data['order_type'] = $order_type;
							$order_data['status'] = 2;     //未支付
							#dump($order_data);die;
							$result = $m_mall_order->add($order_data);
							
							if($result){
								$nums = $m_pay_order->where($map)->count();
								$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
								$form_order_map['order_id'] = $order_id;
								$form_order_map['name'] = $goods_data['name'];
								$form_order_map['money'] = $goods_m_data['goods_money'];
								$form_order_map['type'] = 2;
								$form_order_map['time'] = time();
								$form_order_map['ip'] = get_client_ip();
								$form_order_map['success_time'] = time();
								$form_order_map['success_ip'] = get_client_ip();
								$form_order_map['today'] =  getToday();
								$form_order_map['status'] = 2;
								$order_result = $m_pay_order->add($form_order_map);
								
								$save_order['id'] = $result;
								$save_data['form_order_id'] = $order_id;
								$m_mall_order->where($save_order)->save($save_data);
								
								$array_pay['openid'] = $user_data['weixin_openid'];
								$array_pay['body'] = $goods_user_data['nickname']."-".$goods_data['name'];
								$array_pay['order_sn'] = $order_id;
								$array_pay['total_fee'] = $goods_m_data['goods_money'];
								
								$info = 1;
								
							}else{
								$info = -3;
							}
						
						}else{
							$info = -2;
						}
				}
			}else{
				$info = -6;
			}
			$echo['error_code'] = $info;
			$echo['data'] = $array_pay;
		}else{
			$info = -5;
			$echo['error_code'] = $info;
		}
		#dump($echo);die;
		$echo = json_encode($echo);
		echo $echo;
		
	}
	#余额支付 活动   -4 已经购买 -6 商品不存在  -5 请求错误   -2 票已售罄   1 成功
	public function yue_pay_activity(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		$m_mall_content_money = M("mall_content_money");
		$m_mall_money = M("mall_money");
		
		 if(IS_POST){
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			$goods_type_id = I("param.goods_type_id");
			
			$user_map['id'] = $uid;
			$user_data = $m_common_user->where($user_map)->find();
			
			#商品详情
			$goods_map['id'] = $goods_id;
			$goods_map['type'] = 19;
			$goods_map['status'] = 1;
			$goods_data = $m_mall_content->where($goods_map)->find();
			
			$goods_user_map['id'] = $goods_data['uid'];
			$goods_user_data = $m_common_user->where($goods_user_map)->find();
			
			if(!empty($goods_data)){
				#判断类型 活动
				$order_type = 3;
				#查询是否已购买
				$if_goods_map['goods_id'] = $goods_id;
				$if_goods_map['uid'] = $uid;
				$if_goods_map['status'] = 1;
				$if_goods_data = $m_mall_order->where($if_goods_map)->field('id')->find();
				if($if_goods_data['id'] > 0){
					$info = -4;      //已经购买
				}else{
					$goods_m_map['id'] = $goods_type_id;
					$goods_m_map['goods_id'] = $goods_id;
					$goods_m_data = $m_mall_content_money->where($goods_m_map)->find();
					#dump($goods_m_data);die;
					if($goods_m_data['number'] > 0){
							#生成订单
							$map['today'] = getToday();
							$num = $m_mall_order->where($map)->count();
							
							$order_data['uid'] = $uid;
							$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
							$order_data['name'] = $goods_data['name'];
							$order_data['pay_type'] = 3;
							$order_data['money'] = $goods_m_data['goods_money'];
							$order_data['goods_id'] = $goods_data['id'];
							$order_data['goods_img'] = $goods_data['img'];
							$order_data['goods_num'] = 1;
							$order_data['goods_money'] = $goods_m_data['goods_money'];
							$order_data['goods_type_id'] = $goods_type_id;
							$order_data['tel'] = $user_data['tel'];
							$order_data['time'] = time();
							$order_data['today'] = getToday();
							$order_data['ip'] = get_client_ip();
							$order_data['order_type'] = $order_type;
							$order_data['status'] = 2;     //未支付
							#dump($order_data);die;
							$result = $m_mall_order->add($order_data);
							
							if($result){
								$nums = $m_pay_order->where($map)->count();
								$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
								$form_order_map['order_id'] = $order_id;
								$form_order_map['name'] = $goods_data['name'];
								$form_order_map['money'] = $goods_m_data['goods_money'];
								$form_order_map['type'] = 3;
								$form_order_map['time'] = time();
								$form_order_map['ip'] = get_client_ip();
								$form_order_map['success_time'] = time();
								$form_order_map['success_ip'] = get_client_ip();
								$form_order_map['today'] =  getToday();
								$form_order_map['status'] = 2;
								$order_result = $m_pay_order->add($form_order_map);
								
								$save_order['id'] = $result;
								$save_data['form_order_id'] = $order_id;
								$m_mall_order->where($save_order)->save($save_data);
								
								/* $array_pay['openid'] = $user_data['weixin_openid'];
								$array_pay['body'] = $goods_user_data['nickname']."-".$goods_data['name'];
								$array_pay['order_sn'] = $order_id;
								$array_pay['total_fee'] = $goods_m_data['goods_money']; */
								
								
								#修改pay_order表
								$pay_order_map['order_id'] = $order_id;
								$pay_order_map['status'] = 2;
								$pay_order_datas['status'] = 1;
								
								$dingdan = $m_pay_order->where($pay_order_map)->find();
								$m_pay_order->where($pay_order_map)->save($pay_order_datas);
								if($dingdan){
									#pay_order详情
									$pay_order_map['status'] = 1;
									$pay_order_data = $m_pay_order->where($pay_order_map)->find();
									
									
									#修改 mall_order 表
									$mall_order_map['form_order_id'] = $order_id;
									$mall_order_map['status'] = 2;
									$mall_order_datas['status'] = 1;
									$m_mall_order->where($mall_order_map)->save($mall_order_datas);
									
									#mall_order 详情
									$mall_order_map['status'] = 1;
									$mall_order_data = $m_mall_order->where($mall_order_map)->find();
									
									//商品详情
									$goods_map['id'] = $mall_order_data['goods_id'];
									$goods_data = $m_mall_content->where($goods_map)->find();
									
									#卖方用户详情
									$goods_user_map['id'] = $goods_data['uid'];
									$goods_user_data = $m_common_user->where($goods_user_map)->find();
									
									#活动
									#买方支出记录
									$mall_money_data['uid'] = $user_data['id'];
									$mall_money_data['type'] = 2;
									$mall_money_data['order_type'] = 3;
									$mall_money_data['type_value'] = "余额购买活动";
									$mall_money_data['begin_money'] = $user_data['money'];
									$mall_money_data['money'] = $pay_order_data['money'];
									$mall_money_data['end_money'] = $user_data['money'] - $pay_order_data['money'];
									$mall_money_data['value'] = $order_id;
									$mall_money_data['time'] = time();
									$mall_money_data['ip'] = get_client_ip();
									$mall_money_data['status'] = 1;
									$res = $m_mall_money->add($mall_money_data);
									
									#卖放收入记录
									$mall_money_data['uid'] = $goods_data['uid'];
									$mall_money_data['type'] = 1;
									$mall_money_data['order_type'] = 3;
									$mall_money_data['type_value'] = "卖出活动门票";
									$mall_money_data['begin_money'] = $goods_user_data['money'];
									$mall_money_data['money'] = $pay_order_data['money'];
									$mall_money_data['end_money'] = $goods_user_data['money'] + $pay_order_data['money'];
									$mall_money_data['value'] = $order_id;
									$mall_money_data['time'] = time();
									$mall_money_data['ip'] = get_client_ip();
									$mall_money_data['status'] = 1;
									$res = $m_mall_money->add($mall_money_data);
									#卖方增加余额
									$user_goods_money = $m_common_user->where($goods_user_map)->setInc("money",$pay_order_data['money']);
									
									#买方扣除金额
									$user_name_money = $m_common_user->where($user_map)->setDec("money",$pay_order_data['money']);
									
									#echo "成功";
									#生成二维码
									$erweima_url = scerweima($order_id);
									$url_order_map['form_order_id'] = $order_id;
									$url_order_map['status'] = 1;
									$url_order_datas['goods_time'] = $erweima_url;
									$m_mall_order->where($url_order_map)->save($url_order_datas);
									
									#库存
									$kucun_map['id'] = $mall_order_data['goods_type_id'];
									$m_mall_content_money->where($kucun_map)->setDec("number");
								}
								
								$info = 1;
								
							}else{
								$info = -3;
							}
						
						}else{
							$info = -2;
						}
				}
			}else{
				$info = -6;
			}
			$echo['error_code'] = $info;
			/* $echo['data'] = $array_pay; */
		}else{
			$info = -5;
			$echo['error_code'] = $info;
		}
		$echo = json_encode($echo);
		echo $echo;
		
	}
	
	
	#余额支付 活动   -4 已经购买 -6 商品不存在  -5 请求错误   -2 票已售罄   1 成功
	public function yue_pay_activity_s(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		$m_mall_content_money = M("mall_content_money");
		$m_mall_money = M("mall_money");
		
		 if(IS_POST){
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			$goods_type_id = I("param.goods_type_id");
			$if_type = I("param.if_type");      //1 专辑    2 活动
			
			if($if_type == 2){
				$user_map['id'] = $uid;
				$user_data = $m_common_user->where($user_map)->find();
				
				#商品详情
				$goods_map['id'] = $goods_id;
				$goods_map['type'] = 19;
				$goods_map['status'] = 1;
				$goods_data = $m_mall_content->where($goods_map)->find();
				
				$goods_user_map['id'] = $goods_data['uid'];
				$goods_user_data = $m_common_user->where($goods_user_map)->find();
				
				if(!empty($goods_data)){
					#判断类型 活动
					$order_type = 3;
					#查询是否已购买
					$if_goods_map['goods_id'] = $goods_id;
					$if_goods_map['uid'] = $uid;
					$if_goods_map['status'] = 1;
					$if_goods_data = $m_mall_order->where($if_goods_map)->field('id')->find();
					if($if_goods_data['id'] > 0){
						$info = -4;      //已经购买
					}else{
						$goods_m_map['id'] = $goods_type_id;
						$goods_m_map['goods_id'] = $goods_id;
						$goods_m_data = $m_mall_content_money->where($goods_m_map)->find();
						#dump($goods_m_data);die;
						if($goods_m_data['number'] > 0){
								#生成订单
								$map['today'] = getToday();
								$num = $m_mall_order->where($map)->count();
								
								$order_data['uid'] = $uid;
								$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
								$order_data['name'] = $goods_data['name'];
								$order_data['pay_type'] = 3;
								$order_data['money'] = $goods_m_data['goods_money'];
								$order_data['goods_id'] = $goods_data['id'];
								$order_data['goods_img'] = $goods_data['img'];
								$order_data['goods_num'] = 1;
								$order_data['goods_money'] = $goods_m_data['goods_money'];
								$order_data['goods_type_id'] = $goods_type_id;
								$order_data['tel'] = $user_data['tel'];
								$order_data['time'] = time();
								$order_data['today'] = getToday();
								$order_data['ip'] = get_client_ip();
								$order_data['order_type'] = $order_type;
								$order_data['status'] = 2;     //未支付
								#dump($order_data);die;
								$result = $m_mall_order->add($order_data);
								
								if($result){
									$nums = $m_pay_order->where($map)->count();
									$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
									$form_order_map['order_id'] = $order_id;
									$form_order_map['name'] = $goods_data['name'];
									$form_order_map['money'] = $goods_m_data['goods_money'];
									$form_order_map['type'] = 3;
									$form_order_map['time'] = time();
									$form_order_map['ip'] = get_client_ip();
									$form_order_map['success_time'] = time();
									$form_order_map['success_ip'] = get_client_ip();
									$form_order_map['today'] =  getToday();
									$form_order_map['status'] = 2;
									$order_result = $m_pay_order->add($form_order_map);
									
									$save_order['id'] = $result;
									$save_data['form_order_id'] = $order_id;
									$m_mall_order->where($save_order)->save($save_data);
									
									/* $array_pay['openid'] = $user_data['weixin_openid'];
									$array_pay['body'] = $goods_user_data['nickname']."-".$goods_data['name'];
									$array_pay['order_sn'] = $order_id;
									$array_pay['total_fee'] = $goods_m_data['goods_money']; */
									
									
									#修改pay_order表
									$pay_order_map['order_id'] = $order_id;
									$pay_order_map['status'] = 2;
									$pay_order_datas['status'] = 1;
									
									$dingdan = $m_pay_order->where($pay_order_map)->find();
									$m_pay_order->where($pay_order_map)->save($pay_order_datas);
									if($dingdan){
										#pay_order详情
										$pay_order_map['status'] = 1;
										$pay_order_data = $m_pay_order->where($pay_order_map)->find();
										
										
										#修改 mall_order 表
										$mall_order_map['form_order_id'] = $order_id;
										$mall_order_map['status'] = 2;
										$mall_order_datas['status'] = 1;
										$m_mall_order->where($mall_order_map)->save($mall_order_datas);
										
										#mall_order 详情
										$mall_order_map['status'] = 1;
										$mall_order_data = $m_mall_order->where($mall_order_map)->find();
										
										//商品详情
										$goods_map['id'] = $mall_order_data['goods_id'];
										$goods_data = $m_mall_content->where($goods_map)->find();
										
										#卖方用户详情
										$goods_user_map['id'] = $goods_data['uid'];
										$goods_user_data = $m_common_user->where($goods_user_map)->find();
										
										#活动
										#买方支出记录
										$mall_money_data['uid'] = $user_data['id'];
										$mall_money_data['type'] = 2;
										$mall_money_data['order_type'] = 3;
										$mall_money_data['type_value'] = "余额购买活动";
										$mall_money_data['begin_money'] = $user_data['money'];
										$mall_money_data['money'] = $pay_order_data['money'];
										$mall_money_data['end_money'] = $user_data['money'] - $pay_order_data['money'] ;
										$mall_money_data['value'] = $order_id;
										$mall_money_data['time'] = time();
										$mall_money_data['ip'] = get_client_ip();
										$mall_money_data['status'] = 1;
										$res = $m_mall_money->add($mall_money_data);
										
										#卖放收入记录
										$mall_money_data['uid'] = $goods_data['uid'];
										$mall_money_data['type'] = 1;
										$mall_money_data['order_type'] = 3;
										$mall_money_data['type_value'] = "卖出活动门票";
										$mall_money_data['begin_money'] = $goods_user_data['money'];
										$mall_money_data['money'] = $pay_order_data['money'];
										$mall_money_data['end_money'] = $goods_user_data['money'] + $pay_order_data['money'];
										$mall_money_data['value'] = $order_id;
										$mall_money_data['time'] = time();
										$mall_money_data['ip'] = get_client_ip();
										$mall_money_data['status'] = 1;
										$res = $m_mall_money->add($mall_money_data);
										#卖方增加余额
										$user_goods_money = $m_common_user->where($goods_user_map)->setInc("money",$pay_order_data['money']);
										#买方扣除金额
										$user_name_money = $m_common_user->where($user_map)->setDec("money",$pay_order_data['money']);
										#echo "成功";
										#生成二维码
										$erweima_url = scerweima($order_id);
										$url_order_map['form_order_id'] = $order_id;
										$url_order_map['status'] = 1;
										$url_order_datas['goods_time'] = $erweima_url;
										$m_mall_order->where($url_order_map)->save($url_order_datas);
										
										#库存
										$kucun_map['id'] = $mall_order_data['goods_type_id'];
										$m_mall_content_money->where($kucun_map)->setDec("number");
									}
									
									$info = 1;
									
								}else{
									$info = -3;
								}
							
							}else{
								$info = -2;
							}
					}
				}else{
					$info = -6;
				}
			}else{
				
				$user_map['id'] = $uid;
				$user_data = $m_common_user->where($user_map)->find();
				
				#商品详情
				$goods_map['id'] = $goods_id;
				$goods_map['type'] = array('in','16,22');
				$goods_map['status'] = array('in','1');
				$goods_data = $m_mall_content->where($goods_map)->find();
				
				$goods_user_map['id'] = $goods_data['uid'];
				$goods_user_data = $m_common_user->where($goods_user_map)->find();
				
				if(!empty($user_data) and !empty($goods_data)){
					#判断类型   专辑   二手专辑
					if($goods_data['type'] == 16){
						$order_type = 1;
						$order_status = 5;
					}elseif($goods_data['type'] == 22){
						$order_type = 2;
						$order_status = 3;
					}
					
					#查询是否购买
					$if_goods_map['isrc'] = $goods_data['isrc'];
					$if_goods_map['uid'] = $uid;
					$if_goods_data = $m_mall_content->where($if_goods_map)->field('id')->find();
					if($if_goods_data['id'] > 0){
						$info = -4;
					}else{
						if($goods_data['inventory'] > 0){
							
							#扣余额
							if($goods_data['money'] <= $user_data['money']){
								#生成订单
								$map['today'] = getToday();
								$num = $m_mall_order->where($map)->count();
								
								$order_data['uid'] = $uid;
								$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
								$order_data['name'] = $goods_data['name'];
								$order_data['pay_type'] = 3;
								$order_data['money'] = $goods_data['money'];
								$order_data['goods_id'] = $goods_data['id'];
								$order_data['goods_img'] = $goods_data['img'];
								$order_data['goods_num'] = 1;
								$order_data['goods_money'] = $goods_data['money'];
								$order_data['tel'] = $user_data['tel'];
								$order_data['time'] = time();
								$order_data['today'] = getToday();
								$order_data['ip'] = get_client_ip();
								$order_data['order_type'] = $order_type;
								$order_data['status'] = 2;     //未支付
								$order_data['spending'] = 1;     //支出
								$result = $m_mall_order->add($order_data);
								
								
								$money_result = $m_common_user->where($user_map)->setDec("money",$goods_data['money']);
								$money_results = $m_common_user->where($user_map)->setInc("integral",$goods_data['money']);   //pm票
								
								if($money_result){
								
									$nums = $m_pay_order->where($map)->count();
									$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
									$form_order_map['order_id'] = $order_id;
									$form_order_map['name'] = $goods_data['name'];
									$form_order_map['money'] = $goods_data['money'];
									$form_order_map['type'] = 3;
									$form_order_map['time'] = time();
									$form_order_map['ip'] = get_client_ip();
									$form_order_map['success_time'] = time();
									$form_order_map['success_ip'] = get_client_ip();
									$form_order_map['today'] =  getToday();
									$form_order_map['status'] =  1;
									$order_result = $m_pay_order->add($form_order_map);
									
									$save_order['id'] = $result;
									$save_data['form_order_id'] = $order_id;
									$save_data['status'] = 1;
									$m_mall_order->where($save_order)->save($save_data);
									
									#支付成功，给该专辑做库存处理，
									$m_mall_content->where($goods_map)->setInc("sale");
									$m_mall_content->where($goods_map)->setDec("inventory");
									
									#查询库存 若为1 卖出后为0 则修改商品状态
									if($goods_data['inventory'] <= 1){
										$order_status_data['status'] = $order_status;
										$m_mall_content->where($goods_map)->save($order_status_data);
									}
									
									
									#给卖方增加余额
									$mai_user_map['id'] = $goods_data['uid'];
									$m_common_user->where($mai_user_map)->setInc("money",$goods_data['money']);
									
									
									
									#买方支出记录
									$mall_money_data['uid'] = $user_data['id'];
									$mall_money_data['type'] = 2;
									$mall_money_data['order_type'] = 3;
									$mall_money_data['type_value'] = "余额购买专辑";
									$mall_money_data['begin_money'] = $user_data['money'];
									$mall_money_data['money'] = $goods_data['money'];
									$mall_money_data['end_money'] = $user_data['money'] - $goods_data['money'];
									$mall_money_data['value'] = $order_data['order_id'];
									$mall_money_data['time'] = time();
									$mall_money_data['ip'] = get_client_ip();
									$mall_money_data['status'] = 1;
									$res = $m_mall_money->add($mall_money_data);
									
									#卖放收入记录
									$mall_money_data['uid'] = $goods_data['uid'];
									$mall_money_data['type'] = 1;
									$mall_money_data['order_type'] = 3;
									$mall_money_data['type_value'] = "卖出专辑";
									$mall_money_data['begin_money'] = $goods_user_data['money'];
									$mall_money_data['money'] = $goods_data['money'];
									$mall_money_data['end_money'] = $goods_user_data['money'] + $goods_data['money'];
									$mall_money_data['value'] = $order_data['order_id'];
									$mall_money_data['time'] = time();
									$mall_money_data['ip'] = get_client_ip();
									$mall_money_data['status'] = 1;
									$res = $m_mall_money->add($mall_money_data);
									
									
									#生成我的专辑处理
									$goods_data['uid'] = $uid;
									$goods_data['type'] = 22;
									$goods_data['time'] = time();
									$goods_data['inventory'] = 1;
									$goods_data['original_money'] = $goods_data['money'];
									$goods_data['sale'] = 0;
									$goods_data['status'] = 2;
									unset($goods_data['id']);
									$my_goods_result = $m_mall_content->add($goods_data);
									
									#创建风格关联
									$add_style_array = explode(',',$goods_data['style']);
									
									foreach($add_style_array as $i=>$v){
										if($add_style_array[$i]){
											$add_style_app['style_id'] = $add_style_array[$i];
											$add_style_app['style_table'] = 2;
											$add_style_app['music_id'] = $my_goods_result;
											$m_cms_style->add($add_style_app);
										}
									}
									
									#查询专辑下歌曲
									$my_goods_song['form_id'] = $goods_map['id'];
									$my_goods_song['type'] = 17;
									$my_goods_song['status'] = 1;
									$my_goods_list = $m_mall_content->where($my_goods_song)->select();
									#dump($my_goods_list);die;
									foreach($my_goods_list as $i=>$v){
										#查询歌曲图片并且重新添加
										$my_img_map['type'] = array("in",'2,3');
										$my_img_map['status'] = 1;
										$my_img_map['form_id'] = $my_goods_list[$i]['id'];
										$my_img_list = $m_mall_content_img->where($my_img_map)->select();
										
										$my_goods_list[$i]['form_id'] = $my_goods_result;
										unset($my_goods_list[$i]['id']);
										
										$my_img_result = $m_mall_content->add($my_goods_list[$i]);
										
										foreach($my_img_list as $ii=>$vv){
											unset($my_img_list[$ii]['id']);
											$my_img_list[$ii]['form_id'] = $my_img_result;
											$m_mall_content_img->add($my_img_list[$ii]);
										}
									}
									$info = 1;
								}else{
									
									$info = -3;
								}
							}else{
								$info = -1;
							}
							
							
						}else{
							$info = -2;
						}
					
					}
					
				}else{
					$info = -6;
				}
				
					
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $info;
			/* $echo['data'] = $array_pay; */
		}else{
			$info = -5;
			$echo['error_code'] = $info;
			$echo['data'] = $info;
		}
		$echo = json_encode($echo);
		echo $echo;
		
	}
	
	
	
	# 我喜欢的专辑
	public function openid(){
	   
		//code 换取 openid
		$res= getcurls($url);
		echo $res;
	}
	
	#掏专辑中的二手专辑
	public function er_album(){
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_common_user = M("common_user");
		if(IS_POST){
			#第一个默认偏好风格
			$map['type'] = get_mall_model_conf('MALL_STYLE');
			$map['status'] = 1;
			$data = $m_mall_content->where($map)->field("img,name,id")->order('sort desc')->limit(1)->find();
			$data['img'] = "http://".$_SERVER['HTTP_HOST'].$data['img'];
			
			$style_id = I("param.style_id")?I("param.style_id"):$data['id'];
			
			#查询偏好风格下的专辑
			$tuijian_map['style_id'] = $style_id;
			$tuijian_map['style_table'] = 2;      //表示专辑
			$tuijian_list = $m_cms_style->field('music_id')->where($tuijian_map)->select();
			
			#改为一维数组并且去重
			$tuijian_array = array_column($tuijian_list,'music_id');
			$tuijian_array = array_unique($tuijian_array);
			
			$tuijian_str = implode(',',$tuijian_array);
			
			#该风格下的专辑
			$tuijian_str_map['id'] = array('in',$tuijian_str);
			$tuijian_str_map['status'] = 1;
			#$tuijian_str_map['recommended'] = 1;
			$tuijian_str_map['type'] = 22;
			$tuijian_str_list = $m_mall_content->where($tuijian_str_map)->field("id,uid,img,name,release_time,singer,money,original_money")->order("sort desc")->select();
			/* dump($tuijian_str_list);die; */
			foreach($tuijian_str_list as $i=>$v){
				$tuijian_str_list[$i]['img'] = if_url($tuijian_str_list[$i]['img']);
				$tuijian_str_list[$i]['release_time'] = date("Y-m-d H:i",$tuijian_str_list[$i]['release_time']);
				$uid_map['id'] = $tuijian_str_list[$i]['uid'];
				$uid_map['status'] = 1;
				$uid_name = $m_common_user->where($uid_map)->find();
				$tuijian_str_list[$i]['nickname'] = $uid_name['nickname'];
				unset($tuijian_str_list[$i]['uid']);
			}
			
			$echo['error_code'] = 1;
			$echo['data'] = $tuijian_str_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	
	#收入明细    音乐人
	public function income_detail(){
		$m_common_user = M("common_user");
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_mall_money = M("mall_money");
		
		if(IS_POST){
			#参数  用户id
			$uid = I('param.uid');
			#$uid = 1;
			if($uid > 0){
				$user_map['id'] = $uid;
				$user_map['status'] = 1;
				$user_name = $m_common_user->where($user_map)->find();
				
				$a_map['uid'] = $uid;
				$a_map['type'] = 16;
				$a_map['status'] = array("neq",0);
				$a_list = $m_mall_content->where($a_map)->field("id,name,img,money,sale,inventory,status")->select();
				foreach($a_list as $i=>$v){
					$a_list[$i]['img'] = if_url($a_list[$i]['img']);
					
					$a_list[$i]['num'] = $a_list[$i]['sale'] + $a_list[$i]['inventory'];
				}
				
			}
			$echo['error_code'] = 1;
			$echo['data'] = $a_list;
			$echo['money'] = $user_name['money'];
			#dump($echo);die; 
			$echo = json_encode($echo);
			echo $echo;
			
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	#收入明细   普通用户  
	public function income_details(){
		$m_common_user = M("common_user");
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_mall_money = M("mall_money");
		
		if(IS_POST){
			#参数  用户id 
			$uid = I('param.uid');
			#$uid = 1;
			if($uid > 0){
				$user_map['id'] = $uid;
				$user_map['status'] = 1;
				$user_name = $m_common_user->where($user_map)->find();
				
				$mall_money['uid'] = $uid;
				$mall_money['status'] = 1;
				$mall_money['type'] = 1;    //收入
				$mall_money_list = $m_mall_money->where($mall_money)->select();
				
				foreach($mall_money_list as $i=>$v){
					$mall_money_map['order_id'] = $mall_money_list[$i]['value'];
					$order_list = $m_mall_order->where($mall_money_map)->find();
					
					$goods_map['id'] = $order_list['goods_id'];
					$goods_name = $m_mall_content->where($goods_map)->field("id,type,name,money,original_money,intro,img")->find();
					$goods_name['img'] = if_url($goods_name['img']);
					$goods_array[$i] = $goods_name;
					#$goods_array[$i]['spending'] = $order_list['spending'];
				}
			}
			$echo['error_code'] = 1;
			$echo['data'] = $goods_array;
			$echo['money'] = $user_name['money'];
			#dump($echo);die; 
			$echo = json_encode($echo);
			echo $echo;
			
		}else{
			$echo['error_code'] = 0;
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	#我的专辑  购买的   1转卖中  2可转售  3卖出后
	public function er_album_list(){
		$m_mall_content = M("mall_content");
		
		if(IS_POST){
			#参数
			$uid = I("param.uid");
			#$uid = 1;
			if($uid > 0){
				$album_map['type'] = 22;
				$album_map['uid'] = $uid;
				$album_map['status'] = array("in",'1,2,3');
				$album_list = $m_mall_content->where($album_map)->field("id,img,name,money,original_money,status")->select();
				foreach($album_list as $i=>$v){
					$album_list[$i]['img'] = if_url($album_list[$i]['img']);
				}
			}
			$echo['error_code'] = 1;
			$echo['data'] = $album_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo['data'] = array();
			$echo = json_encode($echo);
			echo $echo;
		}
	}
	
	#前端验证码查看
	public function yanzhengma(){
		$m_sms_code = M("sms_code");
		$map['name'] = "13611190178";
		$map['status'] = 2;
		$list = $m_sms_code->where($map)->order("time desc")->select();
		dump($list);
	}
	
	#我得音乐人 音乐数据
	public function my_song(){
		$m_mall_content = M("mall_content");
		$m_cms_recentlys = M("cms_recentlys");
		$m_cms_content_comments = M("cms_content_comments");
		
		if(IS_POST){
			#参数 uid
			$uid = I('param.uid');
			#$uid = 1;
			
			$my_map['uid'] = $uid;
			$my_map['type'] = 15;
			$my_map['status'] = 1;
			$my_song_list = $m_mall_content->where($my_map)->field("id,name")->select();
			
			foreach($my_song_list as $i=>$v){
				$recentlys_map['r_id'] = $my_song_list[$i]['id'];
				$my_song_list[$i]['count'] = $m_cms_recentlys->where($recentlys_map)->count();
				$comments_map['form_id'] = $my_song_list[$i]['id'];
				$my_song_list[$i]['comments_count'] = $m_cms_content_comments->where($comments_map)->count();
			}
			$echo['error_code'] = 1;
			$echo['data'] = $my_song_list;
			#dump($echo);die;
			$echo = json_encode($echo);
			echo $echo;
		}else{
			$echo['error_code'] = 0;
			$echo['data'] = array();
			$echo = json_encode($echo);
			echo $echo;
		}
		
	}
	
	#余额购买活动
	public function buy_activity(){
		$m_mall_content = M("mall_content");
		$m_pay_order = M("pay_order");
		$m_mall_order = M("mall_order");
		$m_common_user = M("common_user");
		$m_mall_content_img = M("mall_content_img");
		$m_mall_content_money = M("mall_content_money");
		$m_mall_money = M("mall_money");
		
		 if(IS_POST){
			#参数
			$uid = I("param.uid");
			$goods_id = I("param.goods_id");
			$goods_type_id = I("param.goods_type_id");
			
			$user_map['id'] = $uid;
			$user_data = $m_common_user->where($user_map)->find();
			
			#商品详情
			$goods_map['id'] = $goods_id;
			$goods_map['type'] = 19;
			$goods_map['status'] = 1;
			$goods_data = $m_mall_content->where($goods_map)->find();
			
			$goods_user_map['id'] = $goods_data['uid'];
			$goods_user_data = $m_common_user->where($goods_user_map)->find();
			
			if(!empty($goods_data)){
				#判断余额是否足够购买  zyd_mall_money
				if($user_data['money'] >= $goods_data['money']){
					#判断类型 活动
					$order_type = 3;
					#查询是否已购买
					$if_goods_map['goods_id'] = $goods_id;
					$if_goods_map['uid'] = $uid;
					$if_goods_map['status'] = 1;
					$if_goods_data = $m_mall_order->where($if_goods_map)->field('id')->find();
					if($if_goods_data['id'] > 0){
						$info = -4;      //已经购买
					}else{
						$goods_m_map['id'] = $goods_type_id;
						$goods_m_map['goods_id'] = $goods_id;
						$goods_m_data = $m_mall_content_money->where($goods_m_map)->find();
						#dump($goods_m_data);die;
						if($goods_m_data['number'] > 0){
								#生成订单
								$map['today'] = getToday();
								$num = $m_mall_order->where($map)->count();
								
								$order_data['uid'] = $uid;
								$order_data['order_id'] = date('ymd',time()).sprintf("%06d",$num+1);
								$order_data['name'] = $goods_data['name'];
								$order_data['pay_type'] = 3;
								$order_data['money'] = $goods_m_data['goods_money'];
								$order_data['goods_id'] = $goods_data['id'];
								$order_data['goods_img'] = $goods_data['img'];
								$order_data['goods_num'] = 1;
								$order_data['goods_money'] = $goods_m_data['goods_money'];
								$order_data['goods_type_id'] = $goods_type_id;
								$order_data['tel'] = $user_data['tel'];
								$order_data['time'] = time();
								$order_data['today'] = getToday();
								$order_data['ip'] = get_client_ip();
								$order_data['order_type'] = $order_type;
								$order_data['status'] = 1;     //未支付
								#dump($order_data);die;
								$result = $m_mall_order->add($order_data);
								
								$nums = $m_pay_order->where($map)->count();
								$order_id = date('ymd',time()).sprintf("%06d",$nums+1);
								$form_order_map['order_id'] = $order_id;
								$form_order_map['name'] = $goods_data['name'];
								$form_order_map['money'] = $goods_m_data['goods_money'];
								$form_order_map['type'] = 3;
								$form_order_map['time'] = time();
								$form_order_map['ip'] = get_client_ip();
								$form_order_map['success_time'] = time();
								$form_order_map['success_ip'] = get_client_ip();
								$form_order_map['today'] =  getToday();
								$form_order_map['status'] = 1;
								$order_result = $m_pay_order->add($form_order_map);
								
								$save_order['id'] = $result;
								$save_data['form_order_id'] = $order_id;
								$m_mall_order->where($save_order)->save($save_data);
								
								
								#买方支出记录
								$mall_money_data['uid'] = $user_data['id'];
								$mall_money_data['type'] = 2;
								$mall_money_data['order_type'] = 2;
								$mall_money_data['type_value'] = "余额购买活动";
								$mall_money_data['begin_money'] = $user_data['money'];
								$mall_money_data['money'] = $goods_m_data['goods_money'];
								$mall_money_data['end_money'] = $user_data['money'] - $goods_m_data['goods_money'];
								$mall_money_data['value'] = $order_data['order_id'];
								$mall_money_data['time'] = time();
								$mall_money_data['ip'] = get_client_ip();
								$mall_money_data['status'] = 1;
								$res = $m_mall_money->add($mall_money_data);
								
								#卖放收入记录
								$mall_money_data['uid'] = $goods_data['uid'];
								$mall_money_data['type'] = 1;
								$mall_money_data['order_type'] = 3;
								$mall_money_data['type_value'] = "卖出活动门票";
								$mall_money_data['begin_money'] = $goods_user_data['money'];
								$mall_money_data['money'] = $goods_m_data['goods_money'];
								$mall_money_data['end_money'] = $goods_user_data['money'] + $goods_m_data['goods_money'];
								$mall_money_data['value'] = $order_data['order_id'];
								$mall_money_data['time'] = time();
								$mall_money_data['ip'] = get_client_ip();
								$mall_money_data['status'] = 1;
								$res = $m_mall_money->add($mall_money_data);
								#卖方增加余额
								$user_goods_money = $m_common_user->where($goods_user_map)->setInc("money",$goods_m_data['goods_money']);
								#echo "成功";
								#生成二维码
								$erweima_url = scerweima($order_data['order_id']);
								
								$url_order_map['order_id'] = $order_data['order_id'];
								$url_order_map['status'] = 1;
								$url_order_datas['goods_time'] = trim($erweima_url,'.');
								$m_mall_order->where($url_order_map)->save($url_order_datas);
								
								#库存
								$kucun_map['id'] = $goods_type_id;
								$m_mall_content_money->where($kucun_map)->setInc("number");
								$m_mall_content_money->where($kucun_map)->setDec("number");
								
								$info = 1;
								
							}else{
								$info = -2;    //门票不足
							}
					}
					
				}else{
					$info = -7;     //余额不足
				}
				
			}else{
				$info = -6;     //商品是否存在
			}
			$echo['error_code'] = $info;
		}else{
			$info = -5;     //请求错误
			$echo['error_code'] = $info;
		}
		#dump($echo);die;
		$echo = json_encode($echo);
		echo $echo;
		
	}
	
	#个人中心
	public function personal(){
		$m_common_user = M("common_user");
		$m_cms_collection = M("cms_collection");
		
		if(IS_POST){
			$uid = I("param.uid");
			#$uid = 1;
			if($uid > 0){
				$user_map['id'] = $uid;
				$user_map['status'] =  1;
				$user_name = $m_common_user->where($user_map)->field("id,img,nickname,fans,money,votes,intro,pay_way,pay_name")->find();
				#查询我关注数量
				$guanzhu_map['type'] = 2;
				$guanzhu_map['uid'] = $uid;
				$user_name['guanzhu_count'] = $m_cms_collection->where($guanzhu_map)->count();
				
				#判断是否是授权   授权的头像了路径不改变
				//dump($user_name);die;
				$user_name['img'] = if_url($user_name['img']);
				
				$echo['data'] = $user_name;
			}else{
				$echo['data'] = array();
			}
			$echo['error_code'] = 1;
			
		}else{
			$echo['error_code'] = 0;
			$echo['data'] = array();
		}
		#dump($echo);die;
		$echo = json_encode($echo);
		echo $echo;
	}
	
	#新歌推荐 xin_song_tui
	public function xin_song_tui(){
		$m_mall_content = M("mall_content");
		$m_cms_style = M("cms_style");
		$m_mall_content_img = M("mall_content_img");
		if(IS_POST){
			
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			$uid = I('param.uid');
			#$uid = 1;
			if($uid > 0){
				$user_style_str = user_style($uid);
				$banner_map['style_id'] = array('in',$user_style_str);
			}
			$banner_map['style_table'] = 1;      //表示banner
			$banner_list = $m_cms_style->field('music_id')->where($banner_map)->select();
			
			#改为一维数组并且去重
			$banner_array = array_column($banner_list,'music_id');
			$banner_array = array_unique($banner_array);
			$banner_str = implode(',',$banner_array);
			#根据偏好查询出来的banner
			$map['id'] = array('in',$banner_str);
			$map['type'] = 15;
			$map['status'] = 1;
			$list = $m_mall_content->where($map)->field("id,name,singer")->order("time desc")->page($p,$page)->select();
			$list = array_column($list,'id');
			$array = song_detail($list,$uid);
			/* foreach($list as $i=>$v){
				$xuanze_img_map['type'] = 1;					
				$xuanze_img_map['form_id'] = $list[$i]['id'];
				$xuanze_img_data = $m_mall_content_img->where($xuanze_img_map)->order("employ desc")->find();
				$list[$i]['img'] = if_url($xuanze_img_data['url']);
			} */
			$echo['error_code'] = 1;
			$echo['data'] = $array;
		}else{
			$echo['error_code'] = 0;
			$echo['data'] = array();
		}
		#dump($echo);die;
		$echo = json_encode($echo);
		echo $echo;
	}
	
	#设置喜欢   type 1单曲  2音乐人  3专辑
	public function if_like_song(){
		$m_cms_collection = M("cms_collection");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		#有的删除，没有的添加喜欢 
		if(IS_POST){
			/* $song_id = '864,922';
			$uid = 1;
			$type = 1; */
			$song_id = I('param.song_id');
			$song_array = explode(',',$song_id);
			$uid = I('param.uid');
			$type = I('param.type');
			
			if($song_id !='' and $uid > 0){
				foreach($song_array as $i=>$v){
					$like_map['type'] = $type; 
					$like_map['form_id'] = $song_array[$i];
					$like_map['uid'] = $uid;
					$like_data = $m_cms_collection->where($like_map)->find();
					if($like_data){
						$d_result = $m_cms_collection->where($like_map)->delete();
						if($d_result){
							if($type == 2){
								#用于粉丝量排行
								$like_user_map['id'] = $song_id;
								$like_user_data = $m_common_user->where($like_user_map)->find();
								if($like_user_data['fans'] >= 1){
									$m_common_user->where($like_user_map)->setDec("fans");
								}
								
							}else if($type == 3){
								#专辑收藏量 -1  用于专辑收藏量排行
								$shoucang_map['id'] = $song_id;
								$m_mall_content->where($shoucang_map)->setDec("album_collection");
							}
						}
						
					}else{
						$like_map['time'] = time();
						$a_result = $m_cms_collection->add($like_map);
						if($a_result){
							if($type == 2){
								#用于粉丝量排行
								$like_user_map['id'] = $song_id;
								$m_common_user->where($like_user_map)->setInc("fans");
							}else if($type == 3){
								#专辑收藏量 +1  用于专辑收藏量排行
								$shoucang_map['id'] = $song_id;
								$m_mall_content->where($shoucang_map)->setInc("album_collection");
							}
						}
						
					}
					$info = 1;
					
				}
			}else{
				$info = -2;   //参数错误
			}
		}else{
			$info = -1;    //请求错误
		}
		$echo['error_code'] = $info;
		$echo['data'] = $info;
		echo json_encode($echo);
	}

	#投票接口
	public function pm_vote_add(){
		$m_common_user = M("common_user");
		$m_common_user_votes = M("common_user_votes");
		if(IS_POST){
			$music_id = I("param.music_id");
			$user_id = I("param.user_id");
			if($music_id>0 and $user_id>0){
				$users_map['id'] = $user_id;
				$users_map['status'] = 1;
				$users_data = $m_common_user->where($users_map)->find();
				if($users_data['integral'] >= 1){
					#判断用户PM票是否足够
					$map['user_id'] = $user_id;
					$map['music_id'] = $music_id;
					$map['number'] = 1;
					$map['time'] = time();
					$map['ip'] = get_client_ip();
					$map['status'] = 1;
					$result = $m_common_user_votes->add($map);
					
					if($result){
						$user_map['id'] = $music_id;
						$user_data = $m_common_user->where($user_map)->setInc("votes");
					}
					$info = 1;
				}else{
					$info = -2;   //PM票不足
				}
				
			}else{
				$info = 0;
			}
			
		}else{
			$info = 0;	
		}
		$echo['error_code'] = $info;
		$echo = json_encode($echo);
		echo $echo;
	}
	
	
	#我的数据统计
	public function my_data(){
		
		$m_common_user = M("common_user");
		$m_cms_collection = M("cms_collection");
		$m_mall_content = M("mall_content");
		$m_cms_recently = M("cms_recently");
		$m_mall_content_money = M("mall_content_money");
		
		#用户信息参数
		$uid = I('param.uid');
		#$uid = 1;
		if(IS_POST){
			$map['id'] = $uid;
			$user_data = $m_common_user->where($map)->field('id,nickname,img,votes,money')->find();
			if($user_data){
				$user_data['votes_num'] = jindu_num($user_data['votes']);
			
				$user_data['img'] = if_url($user_data['img']);
			
			#关注数量
			$guanzhu_map['uid'] = $uid;
			$guanzhu_map['type'] = 2;
			$user_data['guanzhu_count'] = $m_cms_collection->where($guanzhu_map)->field("id")->count();
			
			#粉丝数量
			$fans_map['form_id'] = $uid;
			$fans_map['type'] = 2;
			$user_data['fans_ccount'] = $m_cms_collection->where($fans_map)->field("id")->count();
			
			#单曲 专辑 收听量
			$shouting_map['type'] = array('in','15,16');
			$shouting_map['uid'] = $uid;
			$shouting_list = $m_mall_content->where($shouting_map)->field("id")->select();
			
			$shouting_array = array_column($shouting_list,'id');
			$shouting_array = array_unique($shouting_array);
			$shouting_str = implode(',',$shouting_array);
			
			$recently_map['type'] = array("in",'1,2');
			$recently_map['r_id'] = array("in",$shouting_str);
			$user_data['recently_count'] = $m_cms_recently->where($recently_map)->sum("count");
			
			#歌曲数量
			$song_map['type'] = 15;
			$song_map['uid'] = $uid;
			$song_count = $m_mall_content->where($song_map)->field("id")->count();
				#专辑下歌曲数量
			$album_map['type'] = 16;
			$album_map['uid'] = $uid;
			$album_list = $m_mall_content->where($album_map)->field("id")->select();	
			$album_array = array_column($album_list,'id');
			$album_array = array_unique($album_array);
			$album_str = implode(',',$album_array);
			
			$album_song_map['type'] = 17;
			$album_song_map['uid'] = $uid;
			$album_song_map['form_id'] = array('in',$album_str);
			$album_song_count = $m_mall_content->where($album_song_map)->field("id")->count();
			
			$user_data['song_count'] = $song_count + $album_song_count;
			
			#专辑销量
			$user_data['album_sale'] = $m_mall_content->where($album_map)->sum("sale");
			
			#活动购票 
			$activity_map['type'] = 19;
			$activity_map['uid'] = $uid;
			$activity_list = $m_mall_content->where($activity_map)->field("id")->select();
			
			$activity_array = array_column($activity_list,'id'); 
			$activity_array = array_unique($activity_array);
			$activity_str = implode(',',$activity_array);
			
			$money_map['goods_id'] = array("in",$activity_str);
			$user_data['activity_sale'] = $m_mall_content_money->where($money_map)->sum("sales");
			
			$echo['error_code'] = 1;
			$echo['data'] = $user_data;
			}else{
				$echo['error_code'] = -1;   //参数错误
				$echo['data'] = array();
			}
		}else{
			$echo['error_code'] = 0;     //请求错误
			$echo['data'] = array();
		}
		echo json_encode($echo);

	}
	
	# 增加评论接口
	public function comments(){
		$m_cms_content_comments = M("cms_content_comments");
		$m_cms_content = M("cms_content");
		$m_mall_content = M("mall_content");
		/* $Page = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数 */
		require("StrFilter.class.php");
		
		if(IS_POST){
			
			$white = array();       //白名单  
			$content = I('param.name');     //内容
			#所有敏感字
			$map_m['type'] = get_cms_model_conf('CMS_S_WORD');
			$map_m['status'] = 1;
			$list = $m_cms_content->where($map_m)->field("name")->order('sort desc')->select();
			$list_array = array_column($list,'name');     //黑名单
			
			$obj = new \StrFilter($white,$list_array); 
			$str = $obj->replace($content); 
			
			#参数
			$map['uid'] = I("param.uid");
			$map['comments_id'] = I("param.comments_id");
			$map['type'] = I("param.type");
			$map['form_id'] = I("param.form_id")?I("param.form_id"):0;
			$map['status'] = 1;    //2待审核   1审核通过
			#敏感字替换
			$map['name'] = $str;
			$map['value'] = $content;
			$map['time'] = time();
			$data = $m_cms_content_comments->add($map);
			if($data){
				#增加评论量
				$pinglun_map['id'] = I("param.comments_id");
				$m_mall_content->where($pinglun_map)->setInc("comments_count");
				if($data > 1){
					$info = 1;
				}
				
			}else{
				$info = -2;   //评论失败 
			}
		}else{
			$info = -1;   //请求错误 
		}
		$echo['error_code'] = $info;
		echo json_encode($echo);
	}
	
	
	#查看评论接口
	public function comments_list(){
		$m_cms_content_comments = M("cms_content_comments");
		$m_common_user = M("common_user");
		
		if(IS_POST){
			#参数
			$p = I("param.p")?I("param.p"):1;
			$page = I("param.page")?I("param.page"):10;
			
			$map['comments_id'] = I("param.comments_id");
			$map['status'] = 1;
			$list = $m_cms_content_comments->where($map)->field("uid,time,name,id")->order("time desc")->page($p,$page)->select();
			foreach($list as $i=>$v){
				$u_map['id'] = $list[$i]['uid'];
				$u_map['status'] = 1;
				$u_data = $m_common_user->where($u_map)->field("nickname,img")->find();
				$list[$i]['nickname'] = $u_data['nickname'];
				#判断是否是授权   授权的头像了路径不改变 
				
					$list[$i]['img'] = if_url($u_data['img']);
				
				$list[$i]['time'] = date("Y-m-d H:i",$list[$i]['time']);
				
			}
			$echo['error_code'] = 1;
			$echo['data'] = $list;
		}else{
			$echo['error_code'] = 0;
			$echo['data'] = array();
			
		}
		#dump($echo);die;  
		echo json_encode($echo);
	}
	
	
	#修改资料 
	public function save_my_data(){
		
		$m_common_user = M("common_user");
		
		if(IS_POST){
			$uid =  I("param.uid");
			$img =  I("param.img");
			$nickname =  I("param.nickname");
			$intro =  I("param.intro");
			$pay_way =  I("param.pay_way");
			$pay_name =  I("param.pay_name");
			
			if($uid > 0){
				$map['id'] = $uid;
				if($img){
					$data['img'] = $img;
				}
				if($nickname){
					$data['nickname'] = $nickname;
				}
				if($pay_way){
					$data['pay_way'] = $pay_way;
				}
				if($pay_name){
					$data['pay_name'] = $pay_name;
				}
				if($intro){
					$data['intro'] = $intro;
				}
				
				$result = $m_common_user->where($map)->save($data);
				if($result){
					$info = 1;   //成功
				}else{
					$info = -4;   //失败
				}
			}else{
				$info = -3;   //参数错误
			}
		}else{
			$info = -1;    //请求错误
		}
		$echo['error_code'] = $info;
		echo json_encode($echo);
	}
	
	
	/* 手机号修改 */ 
	public function save_tel(){
		$m_common_user = M("common_user");  
		$m_sms_code = M("sms_code");
		if(IS_POST){
			$code = I('param.code');
			$data['tel'] = I('param.tel');
			$code_map['name'] =  I('param.tel');
			$code_map['code'] = $code;
			$code_map['status'] = 2;
			$code_data = $m_sms_code->where($code_map)->find();
			 $user_name = $m_common_user->where($data)->find();
			# dump($code_map);die;
			 if(!$user_name){
				if($code_data){
					#验证码正确
					$saves['status'] = 1;
					$m_sms_code->where($code_map)->save($saves);
					
					#$data['tel'] = I('param.yuan_tel');
					$data['id'] = I('param.uid');
					$data['status'] =1;
					$save_data['tel'] = I('param.tel');
					$save_data['username'] = I('param.tel');
					
					$result = $m_common_user->where($data)->save($save_data);
					$info = $result;
				}else{
					$info = -1;    
				}
			 }else{
				 $info = -3;
			 }
		}else{
			$info = -2;
		}
		$echo['error_code'] = $info;
		#1表示成功，返回值为id  -1表示验证码错误  -2请求错误  -3表示手机号存在
		echo json_encode($echo);
	}
	
	
	
	
}